#ifndef DFRT_PAGE_MANAGEMENT_H
#define DFRT_PAGE_MANAGEMENT_H

#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include "memory_management.h"
#ifdef __cplusplus
extern "C" {
#endif

struct pagedir_elt {
        void * fp;
        size_t size;
        int usecount;
        bool exclusive;
        bool acquired;
};

static inline bool page_is_acquired( void * page_ptr ) {
    return dfrt_mem_page_is_acquired(page_ptr);
}

bool page_is_wanted( void * page_ptr );

bool page_get_direlt( void * page_ptr, struct pagedir_elt * dir);
void page_incr_count( void * page_ptr,
                      size_t size,
                      bool exclusive,
                      bool acquired );

void  page_managed_acquire( void * page_ptr,
                            size_t size,
                            bool exclusive );

bool  page_dec_count( void * page_ptr,
                      size_t size,
                      bool exclusive );

int pages_acquired();

int pages_wanted();

#ifdef __cplusplus
}
#endif
#endif
